package xx.codeflower.geonames;

import java.util.ArrayList;

import org.geonames.Toponym;
import org.geonames.ToponymSearchCriteria;
import org.geonames.ToponymSearchResult;
import org.geonames.WebService;

import com.briansteen.utils.GeoPosition;

public class Geonames {

	public ArrayList<GeoPosition> getPlaces(String place) {
		ArrayList<GeoPosition> geonames = new ArrayList<GeoPosition>();
		
		System.out.println("Result for: "+place);
		
		 ToponymSearchCriteria searchCriteria = new ToponymSearchCriteria();
		  searchCriteria.setQ(place);
		  ToponymSearchResult searchResult = null;
		try {
			searchResult = WebService.search(searchCriteria);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		  for (Toponym toponym : searchResult.getToponyms()) {
		     System.out.println(toponym.getName()+" "+ toponym.getCountryName());
		     geonames.add(new GeoPosition((float)toponym.getLatitude(), (float)toponym.getLongitude()));
		  }
	
		  return geonames;
	}
	
}
